package net.cathackers.devel.scmp.auth.interfaces;

import net.cathackers.devel.scmp.auth.exceptions.LockedUserException;
import net.cathackers.devel.scmp.auth.exceptions.AuthenticationException;
import net.cathackers.devel.scmp.auth.exceptions.ProxyException;
import net.cathackers.devel.scmp.auth.exceptions.UserNotFoundException;
import net.cathackers.devel.scmp.exceptions.BackendConnectException;
import net.cathackers.devel.scmp.exceptions.BackendException;

public interface AuthenticationOperations {
    
    /***
     * authenticate is the core function of an authenticator, according to the authentication
     * backend it should respond with AuthenticationInformation implementation depends on the
     * authentication status.
     * @param authenticationCredentials the user login credentials.
     * @return
     * @throws UserNotFoundException 
     * @throws LockedUserException TODO
     * @throws UserNotFoundException TODO
     * @throws ProxyException 
     * @throws LockedUserException 
     * @throws AuthenticationException 
     * @throws AuthenticationException TODO
     * @throws BackendException 
     */
    AuthenticationInformation authenticate(AuthenticationCredentials authenticationCredentials) throws UserNotFoundException, ProxyException, LockedUserException, AuthenticationException, BackendException;
    
    /**
     * Update the authentication information based on AuthToken. This method is used for users to be able to change their own
     * authentication information.
     * @param userAuthToken the token of the user you want to modify his information. (must be authenticated already)
     * @param newAuthenticationCredentials
     * @throws ProxyException 
     * @throws UserNotFoundException 
     * @throws BackendConnectException 
     * @throws LockedUserException TODO
     * @throws UserNotFoundException TODO
     * @throws AuthenticationException TODO
     */
    void updateAuthenticationInformation(AuthToken userAuthToken, AuthenticationCredentials newAuthenticationCredentials) throws ProxyException, BackendConnectException, UserNotFoundException;
    
    /**
     * Checks if username is already available in the authentication backend or not.
     * @param username
     * @return true if the user already exists, false if no such user.
     * @throws AuthenticationException 
     * @throws BackendConnectException 
     */
    public boolean isUsernameExist(String username) throws AuthenticationException, BackendConnectException;

    /**
     * destroy the token and set user logged out.
     * @param userAuthToken
     * @throws ProxyException 
     */
    void logout(AuthToken userAuthToken) throws ProxyException;
    /**
     * check if the token is valid (means that the user is still logged in).
     * @param authToken
     * @return
     * @throws ProxyException 
     */
    boolean isAuthTokenValid(AuthToken authToken) throws ProxyException;
}
